﻿using System.Runtime.CompilerServices;
using System.Drawing;
using System.Drawing.Imaging;
//[assembly: InternalsVisibleTo("Tnelab.WebApp")]
namespace Tnelab.WebApp
{
    public class JsCallEventArgs : EventArgs
    {
        public long CallId { get; }
        public int MessageId { get; }
        public string CallInfoJson { get; }
        public object? Result { get; set; }
        public JsCallEventArgs(long callId,int messageId, string callInfoJson)
        {
            CallId = callId;
            MessageId = messageId;
            CallInfoJson = callInfoJson;
        }
    }
    public class PaintEventArg{
        //public int Width { get;private set; }
        //public int Height { get;private set; }
        public Bitmap? Bitmap{ get; set; }
        public IntPtr Hdc { get; set; }
    }
    public class TitleChangedArgs
    {
        public string Title { get; private set; }
        public TitleChangedArgs(string title)
        {
            this.Title = title;
        }
    }
    public enum WebBrowserType { Edge = 1, MBVip = 2, MBWke = 3 }
    public interface IWebBrowser
    {        
        event EventHandler<TitleChangedArgs>? TitleChanged;
        event EventHandler<JsCallEventArgs>? JsCall;
        event EventHandler<EventArgs>? WebViewIsReady;
        event EventHandler<EventArgs>? DOMContentLoaded;
        event EventHandler<PaintEventArg>? Paint;
        IWebWindow? HostWindow { get; }
        void OnHostWindowCreated(IWebWindow parent);
        int? OnHostWindowMessageProc(IntPtr hWnd, uint message, IntPtr wParam, IntPtr lParam);
        Task<string> CallJsAsync(string script);
        void LoadUrl(string url);
        void AddSchemeHandler(string scheme, Func<string, Stream> handler);
        void Dispose();
        WebBrowserType BrowserType { get; }
    }
    //public abstract class WebBrowserBase
    //{
    //    protected Action<Action> UIInvoke { get; private set; }
    //    public event EventHandler<JsCallEventArg>? JsCall;
    //    public event EventHandler<EventArgs>? Ready;

    //    public WebBrowserBase(Action<Action> uiInvoke)
    //    {
    //        if(uiInvoke == null)
    //            throw new ArgumentNullException(nameof(uiInvoke));
    //        UIInvoke = uiInvoke;
    //    }
    //    protected virtual void OnJsCall(JsCallEventArg arg)
    //    {
    //        JsCall?.Invoke(this, arg);
    //    }
    //    protected virtual void OnReady()
    //    {
    //        Ready?.Invoke(this,new EventArgs());
    //    }
    //    public abstract void OnHostWindowCreated(IntPtr handle);
    //    public virtual  int? OnHostWindowMessageProc(IntPtr hWnd, uint message, IntPtr wParam, IntPtr lParam)
    //    {
    //        return null;
    //    }
    //    public abstract Task<string> CallJsAsync(string script);
    //    public abstract void LoadUrl(string url);
    //}
}